package com.example.cloud.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 可通过@Value注解和Environment对象来获取配置属性
 *
 * @author tongyufu
 */
@RefreshScope
@RestController
public class ConfigAction {

    @Value("${from}")
    private String      from;
    @Autowired
    private Environment env;

    /**
     * from
     *
     * @return value
     */
    @RequestMapping("/from")
    public String from() {
        System.out.println("---------" + env.getProperty("from", "没找到from"));
        System.out.println("---------" + env.getProperty("name", "没找到name"));
        return this.from;
    }

}
